﻿

$(document).ready(function () {

    $('#tbl_user_list').tablePagination();
});


function editUser(obj) {
    var currTr = $(obj).closest("tr");
    var currTbody = $(currTr).closest("tbody");
    $(".editShow", currTbody).hide();
    $(".editHide", currTbody).show();
    $(".editShow", currTr).show();
    $(".editHide", currTr).hide();
    $("[name='ddl_right']", currTr).val($("[name='ipt_right']", currTr).val());
}

function cancelEditUser(obj) {
    var currTr = $(obj).closest("tr");
    $(".editShow", currTr).hide();
    $(".editHide", currTr).show();
}

function updateUser(obj) {
    var currTr = $(obj).closest("tr");

    var data = new QueryData("UserManagementProcess.ashx", "UpdateUser");
    data.SetQueryData(currTr, "user_info");
    var json = $.toJSON(data.Data);
    $.ajax({
        type: "POST",
        url: data.URL,
        dataType: "json",
        data: $.toJSON(data.Data),
        success: function (result) {
            if (!checkAjaxResult(result)) {
                return;
            }
            if (result == "True") {
                var balanceChange = $("[name='ipt_balance_change']", currTr);
                var balanceCtl = $("[name='lbl_balance']", currTr);
                if (!isNaN(parseFloat(balanceChange.val()))) {
                    var balance = parseFloat(balanceCtl.text()) + parseFloat(balanceChange.val());
                    balanceCtl.text(balance.toFixed(2));

                }
                balanceChange.val("");
                var ddlRight = $("[name='ddl_right']", currTr);
                $("[name='lbl_right']", currTr).text($("option[value='" + ddlRight.val() + "']", ddlRight).text());
                cancelEditUser(obj);
            }
        },
        error: function (result) {
        }
    });
}

function deleteUser(obj) {
    alert("暂未开放此功能！敬请期待！");
    //$(obj).closest("tr").remove();
    //$('#tbl_user_list').tablePagination();
}